package com.loklok.code.confuse.util;

public class PromptTemplate {

    public static final StringBuilder paramSb = new StringBuilder();
    static {
        paramSb.append("混淆下面的java原始类，混淆后的类命名为:%s，如果原始类引用外部类实体类，那么需要增加前缀：%s，注意混淆后类在原来的字段上增加注解@JsonProperty,value为原字段的近义词，并且Boolean类型字段不允许以is命名开头，%s: \n")
                .append("%s");
    }


    public static final StringBuilder originallyParamVmSb = new StringBuilder();
    static {

        originallyParamVmSb.append("将下面java类生成一个 Velocity 模板，要求如下：\n" +
                "1. 类前缀使用 $!{classPrefix}，如果原始类引用外部类实体类，那么需要增加前缀$!{classPrefix};\n" +
                "2. 将类的每个字段增加注解 @JsonProperty(value = \"$!{xxx}\"),注意 xxx 是字段名, 必须使用 Velocity 变量方式,即 $!{};\n" +
                "3. 生成一个静态方法，方法名为 %s \n" +
                "4. 需要循环打印包，包的参数是 $!{importPackage}, 模板第一行为 package $!{packageName}; \n" +
                "5. 模板里面需要去掉 setter/getter 以及toString、hashCode、equals等方法，类上需要增加@Data 注解; \n").append("%s");

    }

    public static final StringBuilder originallyControllerVmSb = new StringBuilder();
    static {
        originallyControllerVmSb.append("给你一个案例,原 Feign 接口如下： \n")
                .append(" package groot.openApi.external.feign;\n" +
                        "\n" +
                        "@FeignClient(value = \"ironman-dynamic\", configuration = {FeignTokenInterceptor.class, BeanQueryMapEncoderConfig.class}, fallbackFactory = DynamicFeignFallbackFactory.class)\n" +
                        "public interface DynamicFeign {\n" +
                        "\n" +
                        "    @ApiOperation(value = \"添加评论\")\n" +
                        "    @PostMapping(\"/dynamic/app/comment/add/v1\")\n" +
                        "    ResultResponse<CommentSubInfoItemVo> addCommentV1(@RequestBody CommentAddV2Request request) throws Exception;\n" +
                        "\n" +
                        "\n" +
                        "    @ApiOperation(value = \"评论我的-回复详情页\")\n" +
                        "    @GetMapping(\"/dynamic/app/comment/commentDetail\")\n" +
                        "    ResultResponse<List<CommentContent>> commentDetail(@RequestParam Long id);\n" +
                        "} ")
                .append(" 依照原来的Feign生成的 Controller 的 Velocity 模板如下:\n")
                .append(" package $!{packageName};\n" +
                        "\n" +
                        "@Api(tags = \" $!{path} 包社区openApi\")\n" +
                        "@Slf4j\n" +
                        "@RestController\n" +
                        "@RequestMapping(\"/openApi/dynamic/$!{path}\")\n" +
                        "public class $!{classPrefix}OpenApiDynamicController {\n" +
                        "\n" +
                        "    @Autowired\n" +
                        "    private OpenDynamicService openDynamicService;\n" +
                        "\n" +
                        "    @ApiOperation(value = \"添加评论\")\n" +
                        "    @PostMapping(\"/comment/add/v1\")\n" +
                        "    public ResultResponse<$!{classPrefix}CommentSubInfoItemVo> addCommentV1(@RequestBody $!{classPrefix}CommentAddV2Request request) throws Exception {\n" +
                        "        CommentSubInfoItemVo commentSubInfoItemVo = openDynamicService.addCommentV1($!{classPrefix}CommentAddV2Request.to(request));\n" +
                        "        return ResultResponse.success($!{classPrefix}CommentSubInfoItemVo.from(commentSubInfoItemVo));\n" +
                        "    }\n" +
                        "\n" +
                        "    @ApiOperation(value = \"评论我的-回复详情页\")\n" +
                        "    @GetMapping(\"/comment/commentDetail\")\n" +
                        "    public ResultResponse<List<$!{classPrefix}CommentContent>> commentDetail(@ApiParam(value = \"评论id\") @RequestParam Long id) {\n" +
                        "        List<CommentContent> commentContents = openDynamicService.commentDetail(id);\n" +
                        "        return ResultResponse.success(commentContents.stream().map($!{classPrefix}CommentContent::from).collect(Collectors.toList()));\n" +
                        "    }\n" +
                        "}")
                .append(" 注意如下：1. 模板里面通过 @Autowired 注入的 service 形式为: OpenXXXService, XXX 一般是 Feign 的类名去掉 Feign 字符串, 例如 OpenDynamicService；\n" +
                        "2. 入参如果是用 RequestBody 修饰的对象，它会有一个 to 方法，同样的出参会有 from 方法，如果出参是列表，那么需要遍历转换出参；\n" +
                        "3. 基于以上两点和上面的案例，请把如下的 Feign 生成一个 Controller VM 模板：").append(" %s");
    }


    public static String getOriginallyControllerVmPromptTemplate(String code){
        return String.format(originallyControllerVmSb.toString(), code);
    }

    public static String getOriginallyParamVmPromptTemplate(boolean voType, String code){
        String partPrompt;
        if(voType){
            partPrompt = "from：入参是原始类，出参是当前类";
        } else {
            partPrompt = "to：出参是原始类，入参是当前类";
        }
        return String.format(originallyParamVmSb.toString(), partPrompt, code);
    }
}
